/**
 * Created by gaozijian on 2016/12/10.
 */
var initfun=function () {
    //处理导航栏
    var navset=function () {
        var navs=Frame.Helper.LoadIDS(['navbutton','navrect','navbar']);
        navs.navbutton.addEventListener('click',function () {
            navs.navbutton.class('active');
        });
        navs.navrect.addEventListener('mouseleave',function () {
            navs.navbutton.delclass('active');
        });
        //以上设置导航栏事件监听
    };
    var loadpage=function () {
        //此处加载页面
        var load=function (node) {
            var name=node.getAttribute('id');
            var path='content/'+name+'.html';
            Frame.Ajax.loadToNode(node,path,null);
        };
        var ids=['ye','zhuanjiao','hua','ming'];
        var nodes=Frame.Helper.LoadIDSToArray(ids);
        nodes.forEach(function (n) {
            load(n);
        });
    };
    var pageset=function () {
        //此处处理页面切换逻辑
        var seles=Frame.Helper.LoadIDSToArray(['sele1','sele2','sele3','sele4']);
        var navbtns=document.getElementById('navbar').children;
        var now=0;
        var mask=document.getElementById('pagemask');
        var selefun=function (index) {

            mask.css('display','block');
            setTimeout(function () {
                mask.css('display','none');
            },1000);//1s动画
            setTimeout(function () {
                var osele=seles[now];
                var nsele=seles[index];
                osele.removeAttribute('checked');
                nsele.setAttribute('checked','checked');
                now=index;
            },500);//中途执行切换
            var names=['夜','转角','花','明'];
            var name=names[index];
            document.title='心情-'+name;
        };
        for(var t=0;t<navbtns.length;t++){
            var btn=navbtns[t];
            var nfun=null;
            var code="nfun=function(){selefun({0});};".format(t.toString());
            eval(code);
            btn.addEventListener('click',nfun);
        }
        //以上为每个按钮添加对应的监听器 selefun(t)
    };
    navset();
    loadpage();
    pageset();
};
Frame.OnLoad(initfun);